#include "Cusum.h"

//test 13

Cusum::Cusum(bool* bitArray, int bitArraySize) : NistTest(bitArray, bitArraySize)
{
	this->testName = "Cumulative Sum Test";
}


Cusum::~Cusum()
{
}

void Cusum::start() {

	// compute partial Sums. Normalization is done on the fly.
	//TODO: Normalisierung vorher machen?  waere flotter
	int tempSum = 0;
	int maxSum = 0; // equals "z" in docu

	if (!mode)  //forward mode
	for (int k = 0; k < n; k++) {
		for (int i = 0; i <= k; i++) {
			tempSum += 2*bitArray[i]-1;
			if (std::abs(tempSum) > std::abs(maxSum)) maxSum = tempSum;
		}

	}

	if (mode)  //backward mode
	for (int k = n - 1; k >= 0; k--) {
		for (int i = n-1; i >= k; i--) {
			tempSum += 2 * bitArray[i] - 1;
			if (std::abs(tempSum) > maxSum) maxSum = std::abs(tempSum);
		}
	}

	double tempPValue = 1;

	//TODO: wie kann Z bzw maxSum 1.6 werden?! (Beispiel Script 2.13.8)
}